<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

/**
 * Role information class.
 *
 * Role information's CRUD.
 */
class Encrypt_task_model extends CI_Model {
	private $db_name = 'k9deploy_new';
	private $table = 'encrypt_task';
	private $db = null;
	
	/**
	 * Constructor
	 *
	 * Sets the database used for
	 * information.
	 */
	public function __construct() {
		parent::__construct ();
		
		$this->db = $this->load->database ( $this->db_name, TRUE );
	}
	/**
	 * get pack task by task id
	 *
	 * @param
	 *        	unknown app info
	 */
	public function get_task_by_id($id) {
		$where = array (
				'id' => $id 
		);
		$query = $this->db->where ( $where )->get ( $this->table );
		return $query->row_array ();
	}
	
	/**
	 * Get application information
	 * regarding page number and number
	 * per page
	 *
	 * @param
	 *        	integer	page number
	 * @param
	 *        	integer number per
	 *        	page
	 * @return object
	 */
	public function get_tasks($page = 0, $num = 20, $status = 8) {
		if ($page >= 0 && $num > 0)
			$this->db->limit ( $num, $num * $page );
		if ($status != 8) {
			$where = array_merge ( array (
					'status' => $status 
			), $where );
		}
		$this->db->order_by ( "date", "DESC" );
		
		return $this->db->get ( $this->table )->result_array ();
	}
	/**
	 * get count of task
	 * @param int $os
	 * @param int $status
	 * @return int count
	 */
	public function count($status = 8) {
		if ($status != 8) {
			$where = array_merge ( array (
					'status' => $status
			), $where );
		}
		if(!empty($where)){
			$this->db->where ( $where );
		}
		
		$count = $this->db->count_all($this->table);
	
		return $count;
	}
	
	/**
	 * add a pack task
	 *
	 * @param unknown $data        	
	 */
	public function add_task($data) {
		return $this->db->insert ( $this->table, $data );
	}
	
	public function del_task($id){
		return $this->db->delete($this->table, array('id'=>$id));
	}
}
